package com.tuanzi.loan.business.service.galaxycard.impl;

import com.tuanzi.loan.business.entity.galaxycard.GalaxyCardPrivilegeStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.tuanzi.loan.core.aspect.Debug;


import com.tuanzi.loan.business.repository.galaxycard.GalaxyCardPrivilegeStatusJpaRepository;

import com.tuanzi.loan.business.service.galaxycard.GalaxyCardPrivilegeStatusService;
import com.tuanzi.loan.vo.request.galaxycard.GalaxyCardPrivilegeStatusSearchRequest;
import com.tuanzi.loan.vo.response.galaxycard.GalaxyCardPrivilegeStatusSearchResponse;
import com.tuanzi.loan.business.repository.galaxycard.GalaxyCardPrivilegeStatusRepository;
import com.tuanzi.loan.core.vo.PageSearcher;
import org.springframework.data.domain.Page;

import java.util.Map;
import java.util.Objects;

/**
 * 权益状态管理 ServiceImplement
 * @author JinRuiyang 2018/2/9 17:23:44
 */
@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class GalaxyCardPrivilegeStatusServiceImpl implements GalaxyCardPrivilegeStatusService {

    @Autowired
    private GalaxyCardPrivilegeStatusRepository galaxycardprivilegestatusRepository;

    @Autowired
    private GalaxyCardPrivilegeStatusJpaRepository galaxycardprivilegestatusJpaRepository;


    /**
     * GalaxyCardPrivilegeStatus查询
     * @param pageSearcher 请求信息
     * @return 响应列表
     */
    public Page<GalaxyCardPrivilegeStatusSearchResponse> list(PageSearcher<GalaxyCardPrivilegeStatusSearchRequest> pageSearcher) {
        if (Objects.isNull(pageSearcher))
            throw new NullPointerException("pageSearcher is null");
        if (Objects.isNull(pageSearcher.getSearchCondition()) || Objects.isNull(pageSearcher.getPageable()))
            throw new NullPointerException("galaxycardprivilegestatusSearchRequest or pageable is null");
        return galaxycardprivilegestatusRepository.list(pageSearcher.getSearchCondition(),pageSearcher.getPageable());
    }

    @Override
    public Map<String, Long> getPrivilegeList() {
        return galaxycardprivilegestatusRepository.getPrivilegeList();
    }

    @Override
    public void add(GalaxyCardPrivilegeStatus status) {
        galaxycardprivilegestatusJpaRepository.save(status);
    }

    @Override
    public void edit(GalaxyCardPrivilegeStatus status) {
        galaxycardprivilegestatusJpaRepository.save(status);
    }

    @Override
    public GalaxyCardPrivilegeStatus findById(Long id) {
        return galaxycardprivilegestatusJpaRepository.findOne(id);
    }

    @Override
    public void delete(Long id) {
        galaxycardprivilegestatusJpaRepository.delete(id);
    }
}